package DB;

import java.sql.*;
import java.util.Calendar;

public class DAO {

	private Connection con = null;
	private Statement stmt = null;
	private ResultSet rs = null;
	private VO data;

	private int projectIdx;
	private int zoneIdx;
	private int wallIdx;
	private String update_date;

	public DAO(VO data) {
		this.data = data;

		try {
			Class.forName("org.gjt.mm.mysql.Driver").newInstance();
			con = DriverManager
					.getConnection(
							"jdbc:mysql://127.0.0.1:3306/BESS?useUnicode=true&characterEncoding=euckr",
							"root", "1234");
			System.out.println("BESS db is successfully Connected.");
			stmt = con.createStatement();

			// Projectidx
			rs = stmt
					.executeQuery("Select max(projectIdx) as max from tb_project;");

			while (rs.next()) {
				projectIdx = rs.getInt("max");
				projectIdx++;
			}

			// zoneIdx
			rs = stmt.executeQuery("Select max(zoneIdx) as max from tb_zone;");

			while (rs.next()) {
				zoneIdx = rs.getInt("max");
				zoneIdx++;
			}

			rs = stmt.executeQuery("Select max(wallIdx) as max from tb_wall;");

			while (rs.next()) {
				wallIdx = rs.getInt("max");
				wallIdx++;
			}

			// update_date
			Calendar now = Calendar.getInstance();
			int year = now.get(Calendar.YEAR);
			int month = now.get(Calendar.MONTH) + 1;
			int day = now.get(Calendar.DATE);
			int hour = now.get(Calendar.HOUR);
			int minuate = now.get(Calendar.MINUTE);
			int second = now.get(Calendar.SECOND);
			update_date = year + "-" + month + "-" + day + " " + hour + ":"
					+ minuate + ":" + second;

		} catch (Exception e) {
			System.out.println("Exception" + e);
		}
	}

	public void load() {
		try {
			load_tb_project();
			load_tb_zone();

			load_tb_biomass();
			load_tb_chp();
			load_tb_coal();
			load_tb_cooling();
			load_tb_fuelcell();
			load_tb_geoheatpump();
			load_tb_heating();
			load_tb_hvac();
			load_tb_hws();
			load_tb_light();
			load_tb_micro();
			load_tb_ocean();
			load_tb_pv();
			load_tb_solarheat();
			load_tb_trash();
			load_tb_wall();
			load_tb_water();
			load_tb_window();
			load_tb_windturbine();

			closeDB();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void save() {
		try {
			save_tb_project();
			// Projectidx
			rs = stmt
					.executeQuery("Select max(projectIdx) as max from tb_project;");

			while (rs.next()) {
				projectIdx = rs.getInt("max");
			}
			save_tb_zone();

			save_tb_biomass();
			save_tb_chp();
			save_tb_coal();
			save_tb_cooling();
			save_tb_fuelcell();
			save_tb_geoheatpump();
			save_tb_heating();
			save_tb_hvac();
			save_tb_hws();
			save_tb_light();
			save_tb_micro();
			save_tb_ocean();
			save_tb_pv();
			save_tb_solarheat();
			save_tb_trash();
			save_tb_wall();
			save_tb_water();
			save_tb_window();
			save_tb_windturbine();

			closeDB();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	private void closeDB() {
		if (rs != null)
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		if (stmt != null) {
			try {
				stmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (con != null)
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
	}

	private void clearDB() throws SQLException {
		String del = "TRUNCATE TABLE tb_biomass;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_chp;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_coal;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_cooling;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_fuelcell;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_geoheatpump;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_heating;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_hvac;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_hws;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_light;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_micro;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_ocean;";
		stmt.execute(del);
		del = "DELETE TABLE tb_project;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_pv;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_solarheat;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_trash;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_wall;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_water;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_window;";
		stmt.execute(del);
		del = "TRUNCATE TABLE tb_windturbine;";
		stmt.execute(del);
		del = "DELETE TABLE tb_zone;";
		stmt.execute(del);
	}

	private void save_tb_biomass() throws SQLException {

		for (int i = 0; i < data.biomass.size(); i++) {
			String tmp = "INSERT INTO tb_biomass"
					+ "( projectIdx, update_date)" + "VALUES" + "('"
					+ projectIdx + "','" + update_date + "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_chp() throws SQLException {

		for (int i = 0; i < data.chp.size(); i++) {
			String tmp = "INSERT INTO tb_chp"
					+ "(projectIdx, capacity, heatToPower, heatEfficiency, update_date, type, fuelType, electricEfficiency)"
					+ "VALUES" + "('" + projectIdx + "','" + "0','" + "0','"
					+ data.chp.get(i).heatEfficiency + "','" + update_date
					+ "','" + data.chp.get(i).type + "','"
					+ data.chp.get(i).fuelType + "','"
					+ data.chp.get(i).electricEfficiency + "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_coal() throws SQLException {

		for (int i = 0; i < data.coal.size(); i++) {
			String tmp = "INSERT INTO tb_coal" + "( projectIdx, update_date)"
					+ "VALUES" + "('" + projectIdx + "','" + update_date
					+ "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_cooling() throws SQLException {

		int temp_zoneIdx = zoneIdx;

		for (int i = 0; i < data.cooling.size(); i++) {
			String tmp = "INSERT INTO tb_cooling"
					+ "(cboCoolingKind, cboFuelType, COP, update_date, zoneIdx)"
					+ "VALUES" + "('" + data.cooling.get(i).cboCoolingKind
					+ "','" + data.cooling.get(i).cboFuelType + "','"
					+ data.cooling.get(i).COP + "','" + update_date + "','"
					+ temp_zoneIdx + "');";
			stmt.execute(tmp);

			temp_zoneIdx++;
		}
	}

	private void save_tb_fuelcell() throws SQLException {

		for (int i = 0; i < data.fuelcell.size(); i++) {
			String tmp = "INSERT INTO tb_fuelcell"
					+ "(projectIdx, capacity, efficiency, update_date)"
					+ "VALUES" + "('" + projectIdx + "','"
					+ data.fuelcell.get(i).capacity + "','"
					+ data.fuelcell.get(i).efficiency + "','" + update_date
					+ "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_geoheatpump() throws SQLException {

		for (int i = 0; i < data.geoheatpump.size(); i++) {
			String tmp = "INSERT INTO tb_geoheatpump"
					+ "(capacity, heatingCOP, coolingCOP, update_date, projectIdx)"
					+ "VALUES" + "('" + data.geoheatpump.get(i).capacity
					+ "','" + data.geoheatpump.get(i).heatingCOP + "','"
					+ data.geoheatpump.get(i).coolingCOP + "','" + update_date
					+ "','" + projectIdx + "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_heating() throws SQLException {

		int temp_zoneIdx = zoneIdx;

		for (int i = 0; i < data.heating.size(); i++) {
			String tmp = "INSERT INTO tb_heating"
					+ "(cboHeatingKind, cboFuelType, COP, update_date, zoneIdx)"
					+ "VALUES" + "('" + data.heating.get(i).cboHeatingKind
					+ "','" + data.heating.get(i).cboFuelType + "','"
					+ data.heating.get(i).COP + "','" + update_date + "','"
					+ temp_zoneIdx + "');";
			stmt.execute(tmp);
			temp_zoneIdx++;
		}
	}

	private void save_tb_hvac() throws SQLException {

		int temp_zoneIdx = zoneIdx;

		for (int i = 0; i < data.hvac.size(); i++) {
			String tmp = "INSERT INTO tb_hvac"
					+ "(cboHVACKind, fanRate, cboHeatRecover, update_date, zoneIdx)"
					+ "VALUES" + "('" + data.hvac.get(i).cboHVACKind + "','"
					+ "0','" + data.hvac.get(i).cboHeatRecover + "','"
					+ update_date + "','" + temp_zoneIdx + "');";
			stmt.execute(tmp);
			temp_zoneIdx++;
		}
	}

	private void save_tb_hws() throws SQLException {

		int temp_zoneIdx = zoneIdx;

		for (int i = 0; i < data.hws.size(); i++) {
			String tmp = "INSERT INTO tb_hws"
					+ "(cboHeatingKind, cboFuelType, COP, update_date, zoneIdx)"
					+ "VALUES" + "('" + data.hws.get(i).cboHeatingKind + "','"
					+ data.hws.get(i).cboFuelType + "','" + data.hws.get(i).COP
					+ "','" + update_date + "','" + temp_zoneIdx + "');";
			stmt.execute(tmp);
			temp_zoneIdx++;
		}
	}

	private void save_tb_light() throws SQLException {

		int temp_zoneIdx = zoneIdx;

		for (int i = 0; i < data.light.size(); i++) {
			String tmp = "INSERT INTO tb_light"
					+ "(cboLightKind, numLSCnt, numWorkTime, update_date, zoneIdx)"
					+ "VALUES" + "('" + data.light.get(i).cboLightKind + "','"
					+ data.light.get(i).numLSCnt + "','" + "0','" + update_date
					+ "','" + temp_zoneIdx + "');";
			stmt.execute(tmp);
			temp_zoneIdx++;
		}
	}

	private void save_tb_micro() throws SQLException {

		for (int i = 0; i < data.micro.size(); i++) {
			String tmp = "INSERT INTO tb_micro" + "( projectIdx, update_date)"
					+ "VALUES" + "('" + projectIdx + "','" + update_date
					+ "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_ocean() throws SQLException {

		for (int i = 0; i < data.ocean.size(); i++) {
			String tmp = "INSERT INTO tb_ocean" + "( projectIdx, update_date)"
					+ "VALUES" + "('" + projectIdx + "','" + update_date
					+ "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_project() throws SQLException {

		for (int i = 0; i < data.project.size(); i++) {
			String tmp = "INSERT INTO tb_project"
					+ "(txtProjectNm, txtInputer, txtGroup, txtCallNumber, txtDate, cboLocation, cboUse, numArea, txtAddress, numFloor, cboBearing, update_date)"
					+ "VALUES" + "('"
					+ data.project.get(i).txtProjectNm
					+ "','"
					+ data.project.get(i).txtInputer
					+ "','"
					+ data.project.get(i).txtGroup
					+ "','"
					+ data.project.get(i).txtCallNumber
					+ "','"
					+ data.project.get(i).txtDate
					+ "','"
					+ data.project.get(i).cboLocation
					+ "','"
					+ data.project.get(i).cboUse
					+ "','"
					+ data.project.get(i).numArea
					+ "','"
					+ data.project.get(i).txtAddress
					+ "','"
					+ data.project.get(i).numFloor
					+ "','"
					+ data.project.get(i).cboBearing
					+ "','"
					+ update_date
					+ "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_pv() throws SQLException {

		for (int i = 0; i < data.pv.size(); i++) {
			String tmp = "INSERT INTO tb_pv"
					+ "(txtArea, cboKind, update_date, projectIdx)" + "VALUES"
					+ "('" + data.pv.get(i).txtArea + "','"
					+ data.pv.get(i).cboKind + "','" + update_date + "','"
					+ projectIdx + "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_solarheat() throws SQLException {

		for (int i = 0; i < data.solarheat.size(); i++) {
			String tmp = "INSERT INTO tb_solarheat"
					+ "(cboKind, txtArea, update_date, projectIdx)" + "VALUES"
					+ "('" + data.solarheat.get(i).cboKind + "','"
					+ data.solarheat.get(i).txtArea + "','" + update_date
					+ "','" + projectIdx + "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_trash() throws SQLException {

		for (int i = 0; i < data.trash.size(); i++) {
			String tmp = "INSERT INTO tb_trash" + "(projectIdx, update_date)"
					+ "VALUES" + "('" + projectIdx + "','" + update_date
					+ "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_wall() throws SQLException {

		for (int i = 0; i < data.wall.size(); i++) {
			int zonecount = data.wall.get(i).zoneIdx;

			String tmp = "INSERT INTO tb_wall"
					+ "(zoneIdx, name, cboWall, cboBearing, numArea, numHeatRate, update_date)"
					+ "VALUES" + "('" + (zoneIdx + zonecount) + "','"
					+ data.wall.get(i).name + "','" + data.wall.get(i).cboWall
					+ "','" + data.wall.get(i).cboBearing + "','"
					+ data.wall.get(i).numArea + "','"
					+ data.wall.get(i).numHeatRate + "','" + update_date
					+ "');";
			stmt.execute(tmp);

		}
	}

	private void save_tb_water() throws SQLException {

		for (int i = 0; i < data.water.size(); i++) {
			String tmp = "INSERT INTO tb_water" + "(projectIdx, update_date)"
					+ "VALUES" + "('" + projectIdx + "','" + update_date
					+ "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_window() throws SQLException {

		for (int i = 0; i < data.window.size(); i++) {
			int wallcount = data.window.get(i).wallIdx;
			int zonecount = data.window.get(i).zoneIdx;

			String tmp = "INSERT INTO tb_window"
					+ "(cboWindowKind, cboWindowFrameKind, hrpHeatRate, txtGeff, wallIdx, afBottom, update_date, zoneIdx)"
					+ "VALUES" + "('" + data.window.get(i).cboWindowKind
					+ "','" + data.window.get(i).cboWindowFrameKind + "','"
					+ data.window.get(i).hrpHeatRate + "','"
					+ data.window.get(i).txtGeff + "','"
					+ (wallIdx + wallcount) + "','"
					+ data.window.get(i).afBottom + "','" + update_date + "','"
					+ (zoneIdx + zonecount) + "');";
			stmt.execute(tmp);
		}
	}

	private void save_tb_windturbine() throws SQLException {

		for (int i = 0; i < data.windturbine.size(); i++) {
			String tmp = "INSERT INTO tb_windturbine"
					+ "(projectIdx, capacity, update_date, efficiency)"
					+ "VALUES" + "('" + projectIdx + "','"
					+ data.windturbine.get(i).capacity + "','" + update_date
					+ "','" + data.windturbine.get(i).efficiency + "');";
			stmt.execute(tmp);
		}
		
	}

	private void save_tb_zone() throws SQLException {

		for (int i = 0; i < data.zone.size(); i++) {
			String tmp = "INSERT INTO tb_zone"
					+ "(projectIdx, cboUse, afBottom, update_date, height, zoneName, structure, number)"
					+ "VALUES" + "('" + projectIdx + "','"
					+ data.zone.get(i).cboUse + "','"
					+ data.zone.get(i).afBottom + "','" + update_date + "','"
					+ data.zone.get(i).height + "','"
					+ data.zone.get(i).zoneName + "','"
					+ data.zone.get(i).structure + "','"
					+ data.zone.get(i).number + "');";
			stmt.execute(tmp);

		}

	}

	private void load_tb_biomass() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_biomass;");
		tb_biomass tmp;

		while (rs.next()) {
			tmp = new tb_biomass();
			tmp.bioMassIdx = rs.getInt("bioMassIdx");
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.update_date = rs.getTimestamp("update_date");
			data.biomass.add(tmp);
		}

		/*
		 * for(int i=0; i<data.biomass.size(); i++) {
		 * System.out.print(data.biomass.get(i).bioMassIdx+" ");
		 * System.out.print(data.biomass.get(i).projectIdx+" ");
		 * System.out.println(data.biomass.get(i).update_date); }
		 */
	}

	private void load_tb_chp() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_chp;");
		tb_chp tmp;

		while (rs.next()) {
			tmp = new tb_chp();
			tmp.CHPIdx = rs.getInt("CHPIdx");
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.capacity = rs.getInt("capacity");
			tmp.heatToPower = rs.getDouble("heatToPower");
			tmp.heatEfficiency = rs.getDouble("heatEfficiency");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.type = rs.getString("type");
			tmp.fuelType = rs.getString("fuelType");
			tmp.electricEfficiency = rs.getString("electricEfficiency");
			data.chp.add(tmp);
		}
	}

	private void load_tb_coal() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_coal;");
		tb_coal tmp;

		while (rs.next()) {
			tmp = new tb_coal();
			tmp.coalIdx = rs.getInt("coalIdx");
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.update_date = rs.getTimestamp("update_date");
			data.coal.add(tmp);
		}
	}

	private void load_tb_cooling() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_cooling;");
		tb_cooling tmp;

		while (rs.next()) {
			tmp = new tb_cooling();
			tmp.CoolingIdx = rs.getInt("CoolingIdx");
			tmp.cboCoolingKind = rs.getString("cboCoolingKind");
			tmp.cboFuelType = rs.getString("cboFuelType");
			tmp.COP = rs.getDouble("COP");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.zoneIdx = rs.getInt("zoneIdx");
			data.cooling.add(tmp);
		}
	}

	private void load_tb_fuelcell() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_fuelcell;");
		tb_fuelcell tmp;

		while (rs.next()) {
			tmp = new tb_fuelcell();
			tmp.fcIdx = rs.getInt("fcIdx");
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.capacity = rs.getDouble("capacity");
			tmp.efficiency = rs.getDouble("efficiency");
			tmp.update_date = rs.getTimestamp("update_date");
			data.fuelcell.add(tmp);
		}
	}

	private void load_tb_geoheatpump() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_geoheatpump;");
		tb_geoheatpump tmp;

		while (rs.next()) {
			tmp = new tb_geoheatpump();
			tmp.geothermyIdx = rs.getInt("geothermyIdx");
			tmp.capacity = rs.getDouble("capacity");
			tmp.heatingCOP = rs.getDouble("heatingCOP");
			tmp.coolingCOP = rs.getDouble("coolingCOP");
			tmp.projectIdx = rs.getString("projectIdx");
			tmp.update_date = rs.getTimestamp("update_date");
			data.geoheatpump.add(tmp);
		}
	}

	private void load_tb_heating() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_heating;");
		tb_heating tmp;

		while (rs.next()) {
			tmp = new tb_heating();
			tmp.HeatingIdx = rs.getInt("HeatingIdx");
			tmp.cboHeatingKind = rs.getString("cboHeatingKind");
			tmp.cboFuelType = rs.getString("cboFuelType");
			tmp.COP = rs.getDouble("COP");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.zoneIdx = rs.getInt("zoneIdx");
			data.heating.add(tmp);
		}
	}

	private void load_tb_hvac() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_hvac;");
		tb_hvac tmp;

		while (rs.next()) {
			tmp = new tb_hvac();
			tmp.HVACIdx = rs.getInt("HVACIdx");
			tmp.cboHVACKind = rs.getString("cboHVACKind");
			tmp.fanRate = rs.getDouble("fanRate");
			tmp.cboHeatRecover = rs.getString("cboHeatRecover");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.zoneIdx = rs.getInt("zoneIdx");
			data.hvac.add(tmp);
		}
	}

	private void load_tb_hws() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_hws;");
		tb_hws tmp;

		while (rs.next()) {
			tmp = new tb_hws();
			tmp.HWSIdx = rs.getInt("HWSIdx");
			tmp.cboHeatingKind = rs.getString("cboHeatingKind");
			tmp.cboFuelType = rs.getString("cboFuelType");
			tmp.COP = rs.getDouble("COP");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.zoneIdx = rs.getInt("zoneIdx");
			data.hws.add(tmp);
		}
	}

	private void load_tb_light() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_light;");
		tb_light tmp;

		while (rs.next()) {
			tmp = new tb_light();
			tmp.lightIdx = rs.getInt("lightIdx");
			tmp.cboLightKind = rs.getString("cboLightKind");
			tmp.numLSCnt = rs.getInt("numLSCnt");
			tmp.numWorkTime = rs.getInt("numWorkTime");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.zoneIdx = rs.getInt("zoneIdx");
			data.light.add(tmp);
		}
	}

	private void load_tb_micro() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_micro;");
		tb_micro tmp;

		while (rs.next()) {
			tmp = new tb_micro();
			tmp.microIdx = rs.getInt("microIdx");
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.update_date = rs.getTimestamp("update_date");
			data.micro.add(tmp);
		}
	}

	private void load_tb_ocean() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_ocean;");
		tb_ocean tmp;

		while (rs.next()) {
			tmp = new tb_ocean();
			tmp.oceanIdx = rs.getInt("oceanIdx");
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.update_date = rs.getTimestamp("update_date");
			data.ocean.add(tmp);
		}
	}

	private void load_tb_project() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_project;");
		tb_project tmp;

		while (rs.next()) {
			tmp = new tb_project();
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.txtProjectNm = rs.getString("txtProjectNm");
			tmp.txtInputer = rs.getString("txtInputer");
			tmp.txtGroup = rs.getString("txtGroup");
			tmp.txtCallNumber = rs.getString("txtCallNumber");
			tmp.txtDate = rs.getString("txtDate");
			tmp.cboLocation = rs.getString("cboLocation");
			tmp.cboUse = rs.getString("cboUse");
			tmp.numArea = rs.getDouble("numArea");
			tmp.txtAddress = rs.getString("txtAddress");
			tmp.numFloor = rs.getInt("numFloor");
			tmp.cboBearing = rs.getString("cboBearing");
			tmp.update_date = rs.getTimestamp("update_date");
			data.project.add(tmp);
		}
	}

	private void load_tb_pv() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_pv;");
		tb_pv tmp;

		while (rs.next()) {
			tmp = new tb_pv();
			tmp.pvIdx = rs.getInt("pvIdx");
			tmp.txtArea = rs.getDouble("txtArea");
			tmp.cboKind = rs.getString("cboKind");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.projectIdx = rs.getString("projectIdx");
			data.pv.add(tmp);
		}
	}

	private void load_tb_solarheat() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_solarheat;");
		tb_solarheat tmp;

		while (rs.next()) {
			tmp = new tb_solarheat();
			tmp.solarheatIdx = rs.getInt("solarheatIdx");
			tmp.cboKind = rs.getString("cboKind");
			tmp.txtArea = rs.getDouble("txtArea");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.projectIdx = rs.getString("projectIdx");
			data.solarheat.add(tmp);
		}
	}

	private void load_tb_trash() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_trash;");
		tb_trash tmp;

		while (rs.next()) {
			tmp = new tb_trash();
			tmp.trashIdx = rs.getInt("trashIdx");
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.update_date = rs.getTimestamp("update_date");
			data.trash.add(tmp);
		}
	}

	private void load_tb_wall() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_wall;");
		tb_wall tmp;

		while (rs.next()) {
			tmp = new tb_wall();
			tmp.wallIdx = rs.getInt("wallIdx");
			tmp.zoneIdx = rs.getInt("zoneIdx");
			tmp.name = rs.getString("name");
			tmp.cboWall = rs.getString("cboWall");
			tmp.cboBearing = rs.getString("cboBearing");
			tmp.numArea = rs.getString("numArea");
			tmp.numHeatRate = rs.getString("numHeatRate");
			tmp.chkWindow = rs.getString("chkWindow");
			tmp.chkDoor = rs.getString("chkDoor");
			tmp.update_date = rs.getTimestamp("update_date");
			data.wall.add(tmp);
		}
	}

	private void load_tb_water() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_water;");
		tb_water tmp;

		while (rs.next()) {
			tmp = new tb_water();
			tmp.waterIdx = rs.getInt("waterIdx");
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.update_date = rs.getTimestamp("update_date");
			data.water.add(tmp);
		}
	}

	private void load_tb_window() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_window;");
		tb_window tmp;

		while (rs.next()) {
			tmp = new tb_window();
			tmp.windowIdx = rs.getInt("windowIdx");
			tmp.cboWindowKind = rs.getString("cboWindowKind");
			tmp.cboWindowFrameKind = rs.getString("cboWindowFrameKind");
			tmp.hrpHeatRate = rs.getDouble("hrpHeatRate");
			tmp.txtGeff = rs.getString("txtGeff");
			tmp.wallIdx = rs.getInt("wallIdx");
			tmp.afBottom = rs.getString("afBottom");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.zoneIdx = rs.getInt("zoneIdx");
			data.window.add(tmp);
		}
	}

	private void load_tb_windturbine() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_windturbine;");
		tb_windturbine tmp;

		while (rs.next()) {
			tmp = new tb_windturbine();
			tmp.wtIdx = rs.getInt("wtIdx");
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.capacity = rs.getDouble("capacity");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.efficiency = rs.getDouble("efficiency");
			data.windturbine.add(tmp);
		}
	}

	private void load_tb_zone() throws SQLException {
		rs = stmt.executeQuery("Select * from tb_zone;");
		tb_zone tmp;

		while (rs.next()) {
			tmp = new tb_zone();
			tmp.projectIdx = rs.getInt("projectIdx");
			tmp.zoneIdx = rs.getInt("zoneIdx");
			tmp.cboUse = rs.getString("cboUse");
			tmp.afBottom = rs.getDouble("afBottom");
			tmp.update_date = rs.getTimestamp("update_date");
			tmp.height = rs.getString("height");
			tmp.zoneName = rs.getString("zoneName");
			tmp.structure = rs.getString("structure");
			tmp.number = rs.getInt("number");
			data.zone.add(tmp);
		}
	}
}
